import request from '@/utils/request';
import {object2Url} from "@/utils/trans";


// oem主平台提现审核接口

export async function examine(params) {
	const res = await request.post('/business/withdraw/examine',params);
	// console.log(res)
	if (res.data.code === 2000) {
	  return res.data;
	}
	return Promise.reject(new Error(res.data.message));

  }

// oem根据提现记录id获取提现的佣金信息

export async function brokeragePageList(params) {
	const res = await request.post('/business/wxbrokerageorder/brokeragePageList ',params);
	// console.log(res)
	if (res.data.code === 2000) {
	  return res.data.data;
	}
	return Promise.reject(new Error(res.data.message));

  }
    /**
 * oem 体现列表的删除
 * @param params 查询条件
 */
	export async function reflectPageListDelete(params) {
		const res = await request.post('/business/withdraw/delete',params);
		// console.log(res)
		if (res.data.code === 2000) {
		  return res.data.data;
		}
		return Promise.reject(new Error(res.data.message));

	  }

    /**
 * oem 体现列表的展示
 * @param params 查询条件
 */
export async function reflectPageList(params) {
	const res = await request.post('/business/withdraw/pageList',params);
	// console.log(res)
	if (res.data.code === 2000) {
	  return res.data.data;
	}
	return Promise.reject(new Error(res.data.message));

  }



/**
 * oem申请体现接口
 * @param params 查询条件
 */
export async function withdrawInsertSelective(params) {
	const res = await request.post('/business/withdraw/insertSelective',params);
	// console.log(res)
	if (res.data.code === 2000) {
	  return res.data;
	}
	return Promise.reject(new Error(res.data.message));

  }

/**
 * oem根据oemId获取账号列表
 * @param params 查询条件
 */
export async function getReceivingAccountList(params) {
	const res = await request.post('/business/receivingaccount/getReceivingAccountList  ',params);
	console.log(res)
	if (res.data.code === 2000) {
	  return res.data;
	}
	return Promise.reject(new Error(res.data.message));

  }


/**
 * oem申请提现头部数据查询
 * @param params 查询条件
 */
export async function getOemWithdrawalInfo(params) {
	const res = await request.post('/business/withdraw/getOemWithdrawalInfo',params);
	console.log(res)
	if (res.data.code === 2000) {
	  return res.data;
	}
	return Promise.reject(new Error(res.data.message));
	// return res
  }



/**
 * oem进件列表删除
 * @param params 查询条件
 */
export async function wechatpayDelete(params) {
	const res = await request.post('/business/wechatpay/delete', params);

	if (res.data.code === 2000) {
	  return res.data;
	}
	return Promise.reject(new Error(res.data.message));
  }

/**
 * oem收款账号删除
 * @param params 查询条件
 */
export async function receivingaccountDelete(params) {
	const res = await request.post('/business/receivingaccount/delete', params);

	if (res.data.code === 2000) {
	  return res.data;
	}
	return Promise.reject(new Error(res.data.message));
  }

  /**
 * oem  收款账号修改
 * @param params 查询条件
 */
export async function updateByPrimaryKeySelective(params) {
	const res = await request.post('/business/receivingaccount/updateByPrimaryKeySelective', params);

	if (res.data.code === 2000) {
	  return res.data;
	}
	return Promise.reject(new Error(res.data.message));
  }
/**
 * oem 账户列表查询
 * @param params 查询条件
 */
export async function accountPageList(params) {
	const res = await request.post('/business/receivingaccount/pageList', params);

	if (res.data.code === 2000) {
	  return res.data.data;
	}
	return Promise.reject(new Error(res.data.message));
  }

/**
 * oem 新增账户
 * @param params 查询条件
 */
export async function insertSelective(params) {
	const res = await request.post('/business/receivingaccount/insertSelective', params);

	if (res.data.code === 2000) {
		// console.log(res.data)
	  return res.data;
	}
	return Promise.reject(new Error(res.data.message));
  }




/**
 * 分页查询代理
 * @param params 查询条件
 */
export async function pageMerchant(params) {
  const res = await request.post('/business/oemAgent/page', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


/**
 * 分页查询代理
 * @param params 查询条件
 */
export async function oemAgentQuery(params) {
  const res = await request.post('/business/oemAgent/page', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 充值余额
 * @param data 商户信息
 */
export async function updateMoney(data) {
  const res = await request.post('/business/oemAgent/updateBalance', data);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 分页查询代理类型
 * @param params 查询条件
 */
export async function pageAgencyType(params) {
  const res = await request.post('/business/agentType/pageList', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加代理类型
 * @param params 查询条件
 */
export async function agencyAdd(params) {
  const res = await request.post('/business/agentType/add', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改代理类型
 * @param data 商户信息
 */
export async function agencyUpdate(data) {
  const res = await request.post('/business/agentType/update', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}



/**
 * 分页查询套餐记录
 * @param params 查询条件
 */
export async function mealPage(params) {
  const res = await request.post('/business/merchanttype/pageList', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询套餐记录
 * @param params 查询条件
 */
export async function mealPageList(params) {
  const res = await request.post('/business/merchanttype/page', params);
  console.log("来了哦："+res)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加套餐
 * @param params 查询条件
 */
export async function mealAdd(params) {
  const res = await request.post('/business/merchanttype/add', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改套餐
 * @param data 商户信息
 */
export async function mealUpdate(data) {
  const res = await request.post('/business/merchanttype/update', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除套餐
 * @param id 用户id
 */
export async function mealDelete(params) {
  const res = await request.post('/business/merchanttype/delete', params);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除套餐
 * @param data 用户id集合
 */
export async function removeMeal(data) {
  const res = await request.post('/business/merchanttype/delete', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 分页查询充值记录
 * @param params 查询条件
 */
export async function rechargeRecord(params) {
  const res = await request.post('/business/oemAgent/rechargeRecord', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 代理端 分页查询充值记录
 * @param params 查询条件
 */
export async function rechargeAgentRecord(params) {
  const res = await request.post('/business/oemAgent/getOemAgentMoney', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


/**
 * 代理端 工作台查询总 余额/点数
 * @param params 查询条件
 */
export async function getOmeCount(params) {
  const res = await request.post('/business/oemAgent/getOmeCount', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}



/**
 * 根据ID查询充值记录
 * @param params 查询条件
 */
/* export async function rechargeRecordPageId(params) {
    console.log("普通日志哦！！！",params)
  const res = await request.post('/business/oemAgent/rechargeRecordPageId', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
 */

 export async function rechargeRecordPageId(id) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    id:id
  };
  let url = `/business/oemAgent/rechargeRecordPageId${object2Url(us)}`
  // let url = `/business/oemAgent/balanceRecordPageId${object2Url(us)}`

  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
 /**
 * 根据id查询用户
 * @param id 用户id
 */
/*export async function rechargeRecordPageId(id) {
   console.log("============我来了========",id);
  const res = await request.get('/business/oemAgent/rechargeRecordPageId/' + id);
  console.log("============我来了========",res.data.code);
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
} */

/**
 * 查询用户列表
 * @param params 查询条件
 */
export async function listUsers(params) {
  const res = await request.post('/system/pageList', params);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询用户
 * @param id 用户id
 */
export async function getUser(id) {
  const res = await request.get('/merchantManagement/merchantAccount/' + id);
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加商户
 * @param data 商户信息
 */
export async function addUser(data) {
  const res = await request.post('/business/oemAgent/add', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改商户
 * @param data 商户信息
 */
export async function updateUser(data) {
  const res = await request.post('/business/oemAgent/update', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 充值余额
 * @param data 商户信息
 */
export async function updateBalance(data) {
  const res = await request.post('/business/oemAgent/updateMoney', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 总平台充值余额
 * @param data 商户信息
 */
export async function updateTotalPlatformBalance(data) {
  const res = await request.post('/business/oemAgent/updateTotalPlatformBalance', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 充值余额记录
 * @param data 商户信息
 */
export async function balanceRecordPageId(id) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  const us = {
    ts,
    ua,
    id:id
  };
  let url = `/business/oemAgent/balanceRecordPageId${object2Url(us)}`

  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}



/**
 * 重置密码
 * @param data 代理信息
 */
export async function resetPassword(data) {
  const res = await request.post('/business/oemAgent/resetPassword', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 删除代理
export async function removeAgent(params) {
  const res = await request.post('/business/oemAgent/delete', params);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
/**
 * 删除用户
 * @param id 用户id
 */
export async function removeUser(params) {
  const res = await request.post('/business/agentType/delete', params);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 删除充值记录用户
 * @param id 用户id
 */
export async function rechargeDelete(params) {
  const res = await request.post('/business/oemAgent/rechargeDelete', params);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除用户
 * @param data 用户id集合
 */
export async function removeUsers(data) {
  const res = await request.post('/business/oemAgent/delete', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}


/**
 * 批量删除代理类型
 * @param data 用户id集合
 */
export async function agentTypeDel(data) {
  const res = await request.post('/business/agentType/delete', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改用户状态
 * @param id 用户id
 * @param status 状态
 */
export async function updateUserStatus(id, status) {
  const res = await request.post('/business/oemAgent/updateStatus', {
    id,
    status
  });
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 重置用户密码
 * @param userId 用户id
 * @param password 密码
 * @returns {Promise<string>}
 */
export async function updateUserPassword(params) {
  const res = await request.post('/auth/user/updatePassword', params);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导入用户
 * @param file excel文件
 */
export async function importUsers(file) {
  const formData = new FormData();
  formData.append('file', file);
  const res = await request.post('/system/user/import', formData);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 检查用户是否存在
 * @param field 检查的字段
 * @param value 字段的值
 * @param id 修改时的id
 */
export async function checkExistence(params) {
  const res = await request.post('/auth/user/existence', params);
  if (res.data.code === 2000 && res.data.data != null) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
